package leetcode;

import org.junit.Test;

public class PalindromeNumber {

	public boolean isPalindrome(int x) {
		if (x < 0) {
			return false;
		}
		String x1 = "" + x;
		StringBuffer buffer = new StringBuffer(x1);
		return buffer.toString().equals(buffer.reverse().toString()) == true ? true : false;
	}

	@Test
	public void test() {
		System.out.println(isPalindrome2(12));
	}

	public boolean isPalindrome2(int x) {
		if (x < 0 || (x % 10 == 0 && x != 0)) {
			return false;
		}
		int tempnum = 0;
		while (x > tempnum) {
			tempnum = tempnum * 10 + x % 10;
			x /= 10;
		}
		return x == tempnum || x == tempnum / 10;
	}
}
